JsonConvert.DeserializeObject options camelcasing c# .net

93

JsonConvert.DeserializeObject options camelcasing c# .net -

var jo = new JObject();
jo["CamelCase"] = 1;

string json = JsonConvert.SerializeObject(jo);
var jObject = JsonConvert.DeserializeObject<ExpandoObject>(json);

var settings = new JsonSerializerSettings()
{
    ContractResolver = new CamelCasePropertyNamesContractResolver()
};

var serialized = JsonConvert.SerializeObject(jObject, settings);

Assert.AreEqual("{\"camelCase\":1}", serialized);

JsonConvert.DeserializeObject options camelcasing c# .net -

Dictionary<string, object> jo = new Dictionary<string, object>();
jo.Add("CamelCase", 1);

var settings = new JsonSerializerSettings()
{
    ContractResolver = new CamelCasePropertyNamesContractResolver()
};

var serialized = JsonConvert.SerializeObject(jo, settings);

Assert.AreEqual("{\"camelCase\":1}", serialized);

Comments

Submit
0 Comments